package com.badibadi.socket;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.os.Handler;
import android.util.Log;

import com.badibadi.infos.Chat_Message_Model;
import com.badibadi.infos.Main_Chat_Hestory_Message_Model;
import com.badibadi.infos.friendShow_Model;
import com.badibadi.mytools.SinaExpressionTools;
import com.badibadi.mytools.Utils;

public class Send_Geshi_Tool {
	/**
	 * 需要启动的socket
	 */
	public static SocThread socketThread = null;
	/**
	 * 心跳连接
	 */
	public static String xintiao = null;

	/**
	 * 新消息列表
	 */
	public static List<Chat_Message_Model> chat_Message_Models = new ArrayList<Chat_Message_Model>();

	/**
	 * 新消息数量
	 */
	public static int new_message_num = 0;

	/**
	 * 好友分组列表公有数据
	 */
	public static List<friendShow_Model> show_Models_Public = new ArrayList<friendShow_Model>();

	public static Handler public_new_mes_handler;

	public static Handler public_new_mes_num_handler;

	public static List<Main_Chat_Hestory_Message_Model> chat_Hestory_Main = new ArrayList<Main_Chat_Hestory_Message_Model>();

	/**
	 * 登陆聊天服务器需要发送的数据
	 * 
	 * @param id
	 *            登陆用户id
	 * @param pass
	 *            登陆用户密码(md5加密型)
	 * @return
	 */
	public static String fengzhuang_Login(String id, String pass) {
		String message = "{\"SIGN\":\"Login\",\"Userid\":\"" + id
				+ "\",\"Pwd\":\"" + pass + "\",\"Remark\":\"备注信息\"}";
		return message;
	}

//	/**
//	 * 聊天发送消息封装的数据
//	 * 
//	 * @param id
//	 *            自己的id
//	 * @param Name
//	 *            直接的名字
//	 * @param to_id
//	 *            对方的id
//	 * @param to_Name
//	 *            对方的名字
//	 * @param mes
//	 *            发送的内容
//	 * @return
//	 */
	public static String fenzhuang_Send(String id, String Name, String to_id,
			String to_Name, String mes) {
		String mess=SinaExpressionTools.replaceAllReplaceToPath(mes);
		
		
		String message = "{\"SIGN\":\"Talk\",\"id\":\"" + id + "\",\"Name\":\""
				+ Name + "\",\"toid\":\"" + to_id + "\",\"toName\":\""
				+ to_Name + "\",\"Msg\":\"" + mess + "\",\"Time\":\""
				+ Utils.Get_System_Time("HH:mm") + "\",\"IsRead\":0}";
		return message;
	}

	/**
	 * 向服务器发送消息，标识对方发给我的消息已读
	 * 
	 * @param id
	 *            我的id
	 * @param to_id
	 *            对方的id
	 * @return
	 */
	public static String fengzhuang_Send_yihuifu(String id, String to_id) {
		String message = "{\"SIGN\":\"ChangeRead\",\"id\":\"" + id
				+ "\",\"toid\":\"" + to_id + "\"}";
		return message;
	}

	/**
	 * 
	 * @param mhandler
	 *            接收
	 * @param mhandlerSend
	 *            发送
	 * @param context
	 */
	public static void startSocket(Handler mhandler, Handler mhandlerSend,
			Handler err_handler, Context context) {
		Send_Geshi_Tool.socketThread = new SocThread(mhandler, mhandlerSend,
				err_handler, context);
		Send_Geshi_Tool.socketThread.start();
	}

	/**
	 * 关闭socket
	 */
	public static void stopSocket() {
		if (Send_Geshi_Tool.socketThread != null) {
			Send_Geshi_Tool.socketThread.isRun = false;
			Send_Geshi_Tool.socketThread.close();
			Send_Geshi_Tool.socketThread = null;
//			   ("socket已终止");
		}
	}
}
